package assets;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.content.Context;

public class Botao {

	public float x, y;
	public int largura, altura;
	
	private BitmapTextureAtlas mapaDeTexturas;
	private TextureRegion regiaoDaTextura;
	public Sprite sprite;
	
	public Botao(final String arquivoDaTextura, Scene cena, final Context contexto, TextureManager tm) {
		criaTextura(arquivoDaTextura, contexto, tm);
		converteTexturaEmSprite();
		adicionaGraficosACena(cena);
	}

	public void criaTextura(final String arquivoDaTextura, final Context contexto, TextureManager tm) {
		mapaDeTexturas = new BitmapTextureAtlas(512, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		regiaoDaTextura = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, arquivoDaTextura, 0, 0);
		tm.loadTexture(mapaDeTexturas);
	}

	public void converteTexturaEmSprite(){
		sprite = new Sprite(0, 0, regiaoDaTextura);
		sprite.setPosition(240, 256);
	}

	public void adicionaGraficosACena(Scene cena) {
		cena.attachChild(sprite);
	}

}
